package cn.cs.yangtai.service.impl;

import cn.cs.yangtai.entity.Order;
import cn.cs.yangtai.entity.vo.OrderVo;
import cn.cs.yangtai.entity.vo.PageResult;
import cn.cs.yangtai.mapper.OrderMapper;
import cn.cs.yangtai.service.OrderService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Order)表服务实现类
 *
 * @author makejava
 * @since 2024-12-12 09:22:18
 */
@Service("orderService")
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @Override
    public OrderVo queryById(Integer orderId) {
        return this.orderMapper.queryById(orderId);
    }

    /**
     * 分页查询
     *
     * @param cuttentPage 本页
     * @param pageSize    分页大小
     * @return 查询结果
     */
    @Override
    public PageResult<OrderVo> queryByPage(Integer cuttentPage, Integer pageSize) {
        PageHelper.startPage(cuttentPage,pageSize);
        Page<OrderVo> orders =orderMapper.queryAllByLimit(new Page<>());
        return PageResult.restPage(orders);
    }

    @Override
    public List<OrderVo> queryByUserid(Integer userid) {
        return orderMapper.queryByUserid(userid);
    }

    /**
     * 新增数据
     *
     * @param order 实例对象
     * @return 实例对象
     */
    @Override
    public Order insert(Order order) {
        this.orderMapper.insert(order);
        return order;
    }

    /**
     * 修改数据
     *
     * @param order 实例对象
     * @return 实例对象
     */
    @Override
    public OrderVo update(Order order) {
        this.orderMapper.update(order);
        return this.queryById(order.getOrderId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderId) {
        return this.orderMapper.deleteById(orderId) > 0;
    }
}
